#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
script name: serializable
Created on 2020/3/2 11:19 by PyCharm
@author: fujianjian
"""
from datetime import datetime, date
from uuid import UUID

from flask._compat import text_type
from flask.json import JSONEncoder as JSONEncoder_
from werkzeug.http import http_date

from itsdangerous import json as json_

class JSONEncoder(JSONEncoder_):

    def default(self, o):
        if isinstance(o, datetime):
            return http_date(o.utctimetuple())
            # return o.strftime('%Y-%m-%d %H:%M:%S')
        if isinstance(o, date):
            return http_date(o.timetuple())
        if isinstance(o, UUID):
            return str(o)
        if hasattr(o, 'keys') and hasattr(o, '__getitem__'):
            return dict(o)
        if hasattr(o, '__html__'):
            return text_type(o.__html__)

        return json_.JSONEncoder.default(self, o)


